"""
def factorial(n, acc=1):
    if n == 1:
        return acc
    else:
        return factorial(n - 1, acc * n)


resl = factorial(5)
print(f"reslut = {resl}")


def factorial_tail(n, accumulator=1):
    if n == 0:
        return accumulator
    else:
        # 递归调用是最后的、唯一的操作
        return factorial_tail(n - 1, n * accumulator)
"""


def recur_loop(n):
    sum = 1
    if n == 1:
        return n
    while n > 0:
        sum *= n
        n = n - 1
    return sum


nums = [1, 2, 3, 4, 5, 6]
for num in nums:
    reslut = recur_loop(num)
    print(f"数字{num}的阶乘={reslut}")


# ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit
reslut = recur_loop(10000)

print(f"数字{10000}的阶乘={reslut}")
